#ifndef __BASE_DAEMON_H_
#define __BASE_DAEMON_H_

#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <stdio.h>
#include <fcntl.h>
#include <string>
#include <string.h>
#include <pwd.h>

namespace BASE{
	class Daemon{
		public:
			static void setUser(const std::string & user);

			static bool runDaemon(const char * pidFileName = NULL, const char * stdoutFileName = NULL, const char * stderrFileName = NULL);

			static bool runForkDaemon(const char * pidFileName = NULL, const char * stdoutFileName = NULL, const char * stderrFileName = NULL);

			static bool isPidRunning(const std::string & pidFile);

			static bool isProcessRunning(const std::string & processName);

			static bool savePidAndDupFd(const char * pidFileName, const char * stdoutFileName, const char * stderrFileName);
		private:
	};
}

#endif
